package br.com.cfccultura.admin.view.tag.combo;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.jsp.JspException;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Component;

import br.com.cfccultura.admin.model.dao.IServicoDAO;
import br.com.cfccultura.admin.model.vo.Servico;
import br.com.cfccultura.admin.view.tag.combo.helper.ServicoTagHelper;

@Component
public class ComboServicoTag extends DefaultComboTag {
	
	private static final long serialVersionUID = 1073435506129686702L;
	
	@Override
	public int doStartTagInternal() throws JspException {
		
		IServicoDAO dao = getBean(IServicoDAO.class);

		List<Servico> list = dao.consultar(new Servico());
		List<ServicoTagHelper> helperList = new ArrayList<ServicoTagHelper>();
		for(Servico servico : list) {
			ServicoTagHelper helper = new ServicoTagHelper();
			try {
				BeanUtils.copyProperties(helper, servico);
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			}
			helperList.add(helper);
		}
		buildCombo(helperList, "descricao", "codigo");
		
		return SKIP_BODY;
	}
}
